﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CommonComponent.Common;
using PermissionBase.Core.Domain;
using PermissionBase.Core.Service;

public partial class Admin_Frameset_Title : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        try
        {
            StaffSession ss = SessionUtil.GetStaffSession();
            Staff s = CommonSrv.LoadObjectById(typeof(Staff), ss.LoginId) as Staff;
            lblCurrUserName.Text = s.Name;
            string rolesStr = "";
            if (s.Roles.Count > 0)
            {
                Int32 index = 0;
                foreach (Role role in s.Roles)
                {
                    index++;
                    rolesStr += role.Name;
                    if (index < s.Roles.Count)
                    {
                        rolesStr += "，";
                    }
                }
                lblCurrUserRoles.Text = rolesStr;
            }
            else
            {
                lblCurrUserRoles.Text = "未分配";
            }
            lblCurrDate.Text = System.DateTime.Now.ToString("yyyy-MM-dd");
        }
        catch (MissSessionException)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "reload",
                "<script type=\"text/javascript\">parent.location='../Default.aspx';</script>");
        }
        catch (Exception ex)
        {
            Logger.error(this.ToString(), "session timeout.", ex.Message, "");
        }

    }

    protected void btnLogout_ServerClick(object sender, EventArgs e)
    {
        try
        {
            SessionUtil.RemoveStaffSession();
            SessionUtil.RemoveGrantPermissions();

            FormsAuthentication.SignOut();

            ClientScript.RegisterClientScriptBlock(this.GetType(), "reload",
                "<script type=\"text/javascript\">parent.location='../Default.aspx';</script>");
        }
        catch (Exception ex)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "reload",
                "<script type=\"text/javascript\">parent.location='../Default.aspx';</script>");
        }
    }
}
